<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
<style type="text/css">
	
</style>
<div class="page-header">
	<h1>发起工作流</h1>
</div>

<div class="col-xs-12">
	<table id="dynamic-table" class="table table-striped table-bordered table-hover" style="margin-top:10px">
		<thead>
			<tr>
				<th>工作流名称</th>
				<th>当前状态</th>
				<th>表单设计</th>
				<th>流程设计</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>

<!-- 新增工作流弹窗 -->
<div id="modal-process" class="modal fade">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header no-padding">
				<div class="table-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white">&times;</span>
					</button> 工作流管理
				</div>
			</div>
			<div class="modal-body no-padding">
				<div class="row">
					<div class="col-xs-12">
						<form class="form-horizontal mt10" id="process-form">
							<input type="hidden" name="id" />
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right">所属校区：</label>
								<div class="col-sm-6">
									<input class="form-control" type="text" disabled="" value="<?=$campusInfo['campus_name']?>" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right">工作流名称：</label>
								<div class="col-sm-6">
									<input class="form-control" type="text" name="workflow_title" placeholder="请填写工作流名称"/>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
			<div class="modal-footer no-margin-top" >
				<a href="javascript:;" class="btn btn-sm btn-primary" id="save-process">
					<i class="ace-icon fa fa-check"></i> 保存
				</a>
			</div>
		</div>
	</div>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	var table = "";
	$(function(){
		// 保存工作流按钮
		var processForm = $("#process-form");
		$("#save-process").click(function(){
			processForm.submit();
		})
		var submitUrl = "<?=admin_url('workflow/save_process_action')?>";
		form_submit(processForm, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) window.location.reload();
			});
		})
		// 编辑工作流
		$("body").on("click", ".show-modal", function(){
			processForm.find("[name=id]").val($(this).data("id"))
			processForm.find("[name=workflow_title]").val($(this).data("name"))
		})

		// 删除工作流
		$("body").on("click", ".delete-workflow", function(){
			var id = $(this).data("id");
			layer.confirm('确定删除这个工作流吗？', function(){
				// 提交数据
				var postUrl = "<?=admin_url('workflow/delete_workflow')?>";
				var postData = {"id": id};
				ajax_post(postUrl, postData, function(res){
					table.draw(false);
				})
			});
		})

		// 工作流列表
		table = $('#dynamic-table').dt({
			"ajaxUrl": '<?=admin_url('workflow/get_process_list?state=normal')?>',
			"columns": [
	            {"data": "workflow_title"},
	            {"data": function(ret){
	            	var processState = '<span class="label label-success">正常</span>';
	            	if(ret.workflow_process == '') processState = '<span class="label label-info">待设计流程</span>';
	            	if(ret.workflow_form == '') processState = '<span class="label label-danger">待设计表单</span>';

	            	return processState;
	            }},
	            {"data": function(ret){
	            	return '<a href="<?=admin_url('workflow/check_process_form')?>/'+ ret.id + '"><i class="fa fa-table"></i> 查看表单设计</i></a>';
	            }},
	            
	            {"data": function(ret){
	            	return '<a href="<?=admin_url('workflow/check_process')?>/'+ ret.id + '"><i class="fa fa-table"></i> 查看流程设计</i></a>';
	            }},
	            {"data": function(ret){
                    return '<a href="<?=admin_url('workflow/create_application')?>/'+ ret.id + '"><i class="fa fa-edit"></i> 发起</a>';
	            }},
			]
		});
		
	})
</script>